package com.huawei.esdk.tp.northcommu.cxf.common;

import com.huawei.esdk.platform.common.SDKErrorCode;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.tp.business.common.confctrl.ConfCtrlService;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.AddSiteToConf;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.AddSiteToConfResponse;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.DelSiteFromConf;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.DelSiteFromConfResponse;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.EndConf;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.EndConfResponse;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.SetAudioSwitch;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.SetAudioSwitchResponse;
import com.huawei.esdk.tp.northcommu.cxf.common.gen.TPCommonConfCtr;

public class TPCommonConfCtrlImpl implements TPCommonConfCtr
{
    
    private ConfCtrlService confCtrl;

    @Override
    public EndConfResponse endConf(EndConf parameters)
    {
        EndConfResponse response = new EndConfResponse();
        try
        {
            if(null == parameters)
            {
                response.setResultCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                return response;
            }
            SDKErrorCode code = confCtrl.endConf(parameters.getConfId());
            response.setResultCode(Integer.parseInt(String.valueOf(code.getErrCode())));
        }
        catch (SDKException ex)
        {
            response.setResultCode((int)ex.getSdkErrCode());
        }
        catch (Exception e)
        {
            response.setResultCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return response;
    }

    @Override
    public AddSiteToConfResponse addSiteToConf(AddSiteToConf parameters)
    {
        //定义返回对象soap对象
        AddSiteToConfResponse medicalResponse = new AddSiteToConfResponse();
        //使用领域模型
        SDKErrorCode result = new SDKErrorCode();
        try
        {
            if(null == parameters)
            {
                medicalResponse.setResultCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                return medicalResponse;
            }
            result = confCtrl.addSiteToConf(parameters.getConfId(), parameters.getSiteUri());
            medicalResponse.setResultCode((int)result.getErrCode());
        }
        catch (SDKException ex)
        {
            medicalResponse.setResultCode((int)ex.getSdkErrCode());
        }
        catch (Exception e)
        {
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
            medicalResponse.setResultCode((int)result.getErrCode());
        }
        return medicalResponse;
    }

    @Override
    public DelSiteFromConfResponse delSiteFromConf(DelSiteFromConf parameters)
    {
    	DelSiteFromConfResponse delSiteFromConfResponse = new DelSiteFromConfResponse();
    	SDKErrorCode result = null;
        try
        {
            if(null == parameters)
            {
                delSiteFromConfResponse.setResultCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                return delSiteFromConfResponse;
            }
        	result = confCtrl.delSiteFromConf(parameters.getConfId(), parameters.getSiteUri());
        	if(result != null)
        	{
        		delSiteFromConfResponse.setResultCode((int) result.getErrCode());
        	}
        }      
        catch (SDKException ex)
        {
            delSiteFromConfResponse.setResultCode((int)ex.getSdkErrCode());
        }
        catch (Exception e)
        {
        	if(result != null)
        		delSiteFromConfResponse.setResultCode((int) result.getErrCode());
        }
		
		return delSiteFromConfResponse;
    }

    @Override
    public SetAudioSwitchResponse setAudioSwitch(SetAudioSwitch parameters)
    {
    	SetAudioSwitchResponse setAudioSwitchResponse = new SetAudioSwitchResponse();
    	SDKErrorCode result = null;
        try
        {
            if(null == parameters)
            {
                setAudioSwitchResponse.setResultCode(ErrInfo.SDK_PARAM_NOT_COMPLETE_ERRORCODE);
                return setAudioSwitchResponse;
            }
			result = confCtrl.setAudioSwitch(parameters.getConfId(), parameters.isOnOff());
		    setAudioSwitchResponse.setResultCode((int) result.getErrCode());
        }
        catch (SDKException ex)
        {
            setAudioSwitchResponse.setResultCode((int)ex.getSdkErrCode());
        }
        catch (Exception e)
        {
        	setAudioSwitchResponse.setResultCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }

		return setAudioSwitchResponse;
    }

    public ConfCtrlService getConfCtrl()
    {
        return confCtrl;
    }

    public void setConfCtrl(ConfCtrlService confCtrl)
    {
        this.confCtrl = confCtrl;
    }

}
